package com.linkin.homepage.ui.home;

import androidx.recyclerview.widget.RecyclerView;

import com.linkin.homepage.base.BaseFragment;
import com.linkin.homepage.ui.adapter.ComRCAdapter;
import com.linkin.homepage.view.refresh.RefreshViewUtils;

public class ComListHelper {

    public static void refreshData(BaseFragment fragment, RecyclerView recyclerView, ComRCAdapter newsAdapter) {
        if (newsAdapter.getItemCount() > 0) {
            fragment.showNormal();
            if (!RefreshViewUtils.isRefreshing(recyclerView)) {
                int delay = recyclerView.canScrollVertically(-1) ? 300 : 0;
                recyclerView.stopScroll();
                recyclerView.smoothScrollToPosition(0);
                recyclerView.postDelayed(() -> {
                    recyclerView.stopScroll();
                    recyclerView.scrollToPosition(0);
                    RefreshViewUtils.setRefreshing(recyclerView);
                }, delay);
            }
        } else {
            fragment.showLoading();
            if (!RefreshViewUtils.isRefreshing(recyclerView)) {
                RefreshViewUtils.setRefreshing(recyclerView);
            }
        }
    }

}
